import { Component } from "@angular/core";
import { NavController, NavParams } from "ionic-angular";
import { HttpService } from "./../../../providers/http.service";
import { CommonFunc } from "./../../../providers/commonFunc";
import { appConfig } from "../../../providers/config";

@Component({
  templateUrl: "inform-detail.html"
})
/**
 * 资讯详情
 */
export class InformDetail {
  private informDetailBean: InformDetailBean = new InformDetailBean();
  private imageList: any = [];
  constructor(
    private navController: NavController,
    private navParams: NavParams,
    private httpService: HttpService,
    private commonFunc: CommonFunc
  ) {
    let id = this.navParams.get("id");
    this.httpService.informationById(id).subscribe(data => {
      if (data.status != 200) {
        let toast = this.commonFunc.showInsideErrorToast(data);
        toast.present();
        return;
      }

      this.informDetailBean = data.data;
      if (this.informDetailBean.content) {
        this.informDetailBean.content = decodeURIComponent(
          atob(this.informDetailBean.content)
        );
      }

      if (this.informDetailBean.fileUrls) {
        this.imageList = this.informDetailBean.fileUrls.split(",");
      }
    });
  }
  open(url: string) {
    this.commonFunc.openDocs(url);
  }
}

class InformDetailBean {
  id: string;
  title: string;
  subTitle: string;
  content: string;
  createUserId: string;
  createPartyId: string;
  fileUrls: string;
  createTime: string;
}
